package com.sk.waste.app.adapters

import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.lc.smc.lib.interfaces.LCInterface
import com.lc.smc.lib.utils.LCBaseUtil
import com.sk.waste.app.R
import com.sk.waste.app.config.NetWorkConfig
import com.sk.waste.app.models.TenderModel

/**
 *  @time 2025/01/07  15:37
 *  @desc 招标信息详情-推荐
 */
class RecomentAdapter(private val context: Context, val list: List<TenderModel>, val callback: LCInterface.LcCallBack) :
    RecyclerView.Adapter<RecomentAdapter.ViewHolder>() {


    override fun getItemCount(): Int {
        return list.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecomentAdapter.ViewHolder {
        return ViewHolder(LayoutInflater.from(context).inflate(R.layout.adapter_recomment, parent, false))
    }

    @SuppressLint("NotifyDataSetChanged", "SetTextI18n")
    override fun onBindViewHolder(holder: ViewHolder, @SuppressLint("RecyclerView") position: Int) {

        val item = list[position]
        holder.ttvPrice.text = item.price
        holder.ttvName.text = item.title
        if (!LCBaseUtil.isNull(item.image)) {
            Glide.with(context).load(NetWorkConfig.NET_URL_IMA_ROOT + item.image).transform(CenterCrop(), RoundedCorners(20)).error(R.mipmap.img_item_default).into(holder.imgView);
        }
        holder.rootView.tag = position
        holder.rootView.setOnClickListener {
            val currentSelect = holder.rootView.tag as Int
            callback.callBack(currentSelect)
        }

    }


    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val imgView: ImageView = view.findViewById(R.id.item_tender_picture)
        val ttvPrice: TextView = view.findViewById(R.id.item_tender_price)
        val ttvName: TextView = view.findViewById(R.id.item_tender_name)
        val rootView: LinearLayout = view.findViewById(R.id.item_root_layout)
    }


}